import requests
import json
import uuid

class AssignUploadUrlFirstTrueApi:
    def __init__(self):
        pass

    def assign_upload_url(self, token, appId):
        headers = {
            "User-Agent": "RestSharp/107.3.0.0",
            "Accept": "application/json, text/json, text/x-json, text/javascript, application/xml, text/xml",
            "Content-Type": "application/json; charset=utf-8",
            "timezone": "%2b08%3a00",
            "ipv4": "192.168.43.133",
            "Accept-Language": "zh-CN,zh;q=1",
            "Authorization": f"bearer {token}"
        }
        url = "https://api.winrobot360.com/api/client/app/file/assignUploadUrl"
        data = {
            "appId": appId,
            "appType": "app",
            "version": "",
            "isBot": True
        }

        data = json.dumps(data, separators=(',', ':'))
        response = requests.post(url, headers=headers, data=data)

        try:
            json_data = response.json()
            formatted_json = json.dumps(json_data, indent=4, ensure_ascii=False)
            print("JSON Content:")
            print(formatted_json)
            return json_data
        except json.JSONDecodeError:
            print("Response is not valid JSON")

        # {"data":{"fileKey":"robots/robot-bc6f4832-a9d9-4dda-bd87-f9d23da57fb1/v-1/package.json","uploadUrl":"https://winrobot-pri-a.oss-cn-hangzhou.aliyuncs.com/robots/robot-bc6f4832-a9d9-4dda-bd87-f9d23da57fb1/v-1/package.json?Expires=1764133289&OSSAccessKeyId=LTAI5t93vfGfysekhtsfrZU9&Signature=YXhp2x1KB3%2BXDGCa4ks1uqp2n3k%3D","readUrl":"https://winrobot-pri-a.oss-cn-hangzhou.aliyuncs.com/robots/robot-bc6f4832-a9d9-4dda-bd87-f9d23da57fb1/v-1/package.json?Expires=1764174689&OSSAccessKeyId=LTAI5t93vfGfysekhtsfrZU9&Signature=Piz08ig5aX5mjpdCPxVJ4J%2Fuz%2BY%3D","fileKeyMd5":"6978fcd358e3fd41d4ccc753d88595e1","headers":{}},"code":200,"success":true}


if __name__ == '__main__':
    AssignUploadUrlFirstTrueApi().assign_upload_url()
